using IQIGame.Onigao.Framework;
using IQIGame.Onigao.Game;
using UnityEngine;

namespace IQIGame.Onigao.GamePlay
{
    public class UIN_QuestCell : UIBaseNode
    {

        #region Template Generate,don't modify
        protected partial class UIB_UIN_QuestCell
        {
            #region ObjectBinding Generate
            public IQIGame.Onigao.Framework.ExToggle toggleQuest { protected set; get; }
            public IQIGame.Onigao.Framework.ExText engJinDu { protected set; get; }
            public IQIGame.Onigao.Framework.ExText jinDu { protected set; get; }
            public UnityEngine.GameObject tracking { protected set; get; }
            public IQIGame.Onigao.Framework.ExText title { protected set; get; }
            public virtual void InitBinding(ObjectBinding __binding)
            {
                __binding.TryGetVariableValue<IQIGame.Onigao.Framework.ExToggle>("toggleQuest", out var __tbv0);
                this.toggleQuest = __tbv0;
                __binding.TryGetVariableValue<IQIGame.Onigao.Framework.ExText>("engJinDu", out var __tbv1);
                this.engJinDu = __tbv1;
                __binding.TryGetVariableValue<IQIGame.Onigao.Framework.ExText>("jinDu", out var __tbv2);
                this.jinDu = __tbv2;
                __binding.TryGetVariableValue<UnityEngine.GameObject>("tracking", out var __tbv3);
                this.tracking = __tbv3;
                __binding.TryGetVariableValue<IQIGame.Onigao.Framework.ExText>("title", out var __tbv4);
                this.title = __tbv4;
            }
            #endregion ObjectBinding Generate 
        }
        #endregion Template Generate,don't modify

        #region fields & properties
        private CanvasGroup cvsGroup = null;

        private UD_OneQuest questData = null;

        protected UIB_UIN_QuestCell ui { get; set; }
        #endregion

        protected override void BeforeInit()
        {
            ui = new UIB_UIN_QuestCell();
            ui.InitBinding(this.csObjBind);
        }

        protected override void OnInit()
        {
            this.cvsGroup = this.gameObject.GetOrAdd<CanvasGroup>();
            this.ui.toggleQuest.onValueChanged.AddListener(this.OnTogValueChanged);
        }

        protected override void OnShow()
        {

        }

        protected override void OnHide()
        {

        }

        protected override void OnDispose()
        {

        }

        public void Show(UD_OneQuest questData)
        {
            this.questData = questData;
            if (questData == null)
                return;
            this.Show();
            var questState = questData.questState;
            var cfgData = questData.cfgData;
            this.ui.title.text = cfgData.Name;
            this.ui.jinDu.text = APIUIQuest.GetQuestState(questState);
            this.ui.engJinDu.text = APIUIQuest.GetQuestStateEng(questState);
            bool isTracking = questData.isTracking;
            this.ui.tracking.SetActive(isTracking);
            this.OnTogValueChanged(false);
        }

        void OnTogValueChanged(bool isOn)
        {
            this.cvsGroup.interactable = !isOn;
            //this.ui.engJinDu.indexSwitchColor = isOn ? 1 : 0;
            int indexJinDu = 0;
            if (isOn)
            {
                indexJinDu = 3;
            }
            else
            {
                switch (this.questData.questState)
                {
                    case QuestState.Success:
                    case QuestState.Fails:
                        indexJinDu = 2;
                        break;
                }
            }
            //this.ui.jinDu.indexSwitchColor = indexJinDu;
        }
    }
}
